<template>
	<view class="analyze">
		<u-sticky>
			<view class="sticky">
				<u-cell-item :arrow="false" @click="handleShowAction">
					<view slot="title">
						<text selectable>解析源：</text>
					</view>
					<view>
						<text>{{ site.name }}</text>
						<u-icon name="map"></u-icon>
					</view>
				</u-cell-item>
			</view>
		</u-sticky>
		<u-form ref="uForm" class="u-p-10">
			<u-form-item label="视频地址:" label-position="top">
				<u-input v-model="model.url" type="textarea" placeholder="输入视频播放地址" border />
			</u-form-item>
		</u-form>
		<u-row class="u-p-20">
			<u-col :span="6">
				<u-button type="warning" @click="handleWebAnalyze" :loading="loading">浏览器解析</u-button>
			</u-col>
			<u-col :span="6">
				<u-button type="success" @click="handleAnalyze" :loading="loading">内置解析</u-button>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					url: ''
				},
				site: {
					name: '未知'
				},
				list: [],
				initialtime: '',
				url: '',
				loading: false
			}
		},
		created() {
			this.model.url = 'https://www.iqiyi.com/v_19rrjvej28.html?vfm=2008_aldbd&fc=828fb30b722f3164&fv=p_02_01'
			this.fetchData()
      this.site.name = this.defcku.name
		},
		methods: {
			fetchData() {
				// this.$u.vuex('analyze')
				this.list = this.defcku.analyze
				if (this.list.length > 0) {
					this.site = this.list[0]
				}
			},
			async videoTimeUpdateEvent(e) {
				// 播放进度变化时触发timeupdate，event.detail = {currentTime, duration} 。触发频率 250ms 一次
				this.videoUpdateCounter += 1
				if (this.videoUpdateCounter % 40 === 0) {
					// 每10秒更新一下历史记录的时间进度
					this.videoUpdateCounter = 0
					// await this.updateHistory(e.detail)
				}
			},
			handleShowAction() {
				let rows = this.list.map(t => t.name)
				uni.showActionSheet({
					itemList: rows,
					success: (res) => {
						let model = this.list[res.tapIndex]
						this.site = model
						// console.log(model)
					}
				})
			},
			handleAnalyze() {
				if (!this.site.id) {
					this.$u.toast('请选择解析源！')
					return
				}
				if (!this.site.url) {
					this.$u.toast('解析源配置错误！')
					return
				}
				let url = `${this.site.url}${this.model.url}`
				console.log(url)
				this.$u.route({
					url: '/pages/analyze/webVideo',
					params: { url }
				})
				return
				// this.handleAppAnalyze(url)
				// #ifdef APP-PLUS
				plus.runtime.openURL(url)
				// #endif
				// #ifdef H5
				window.open(url)
				// #endif
				// this.$u.toast('暂未开放')
			},
			handleWebAnalyze() {
				if (!this.site.id) {
					this.$u.toast('请选择解析源！')
					return
				}
				if (!this.site.url) {
					this.$u.toast('解析源配置错误！')
					return
				}
				let url = `${this.site.url}${this.model.url}`
				// #ifdef APP-PLUS
				plus.runtime.openURL(url)
				// #endif
				// #ifdef H5
				window.open(url)
				// #endif
				// this.$u.toast('暂未开放')
			}
		}
	}
</script>

<style lang="scss">
	.analyze {
		.sticky {
			background-color: #FFF;
			box-sizing: border-box;
			border: 0px solid #096;
		}

	}
</style>